package learn;

import learn.link.Node;

import java.util.Arrays;
import java.util.Random;

public class CommUtil {
    public static Random random = new Random();

    /**
     * <=100,随机数组
     * @param len
     * @return
     */
    public static int[] arr(int len) {
        int[] arr = new int[len];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(10);
        }
        return arr;
    }

    public static void printArray(String des,int[] arr){
        System.out.print(des+" : ");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+",");
        }
        System.out.println("");
    }
    public static void printArray(String des,Object[] arr){
        System.out.print(des+" : ");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+",");
        }
        System.out.println("");
    }


    public static void check(int[] old,int[] sorted){
        Arrays.sort(old);

        for (int i = 0; i < old.length; i++) {
            if(old[i]!=sorted[i] ){
                throw new RuntimeException("结果不对");
            }
        }
        System.out.println("结果完全一直");
    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void printLinkedList(Node node) {
        System.out.println();
        System.out.print("Linked List: ");
        while (node != null) {
            System.out.print(node.value + " ");
            node = node.next;
        }
        System.out.println();
    }

    public static void swap(Node[] nodeArr, int a, int b) {
        Node tmp = nodeArr[a];
        nodeArr[a] = nodeArr[b];
        nodeArr[b] = tmp;
    }




}
